﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyNhaSach.DataAccessLayer
{
    class SachDAO
    {
        DataConnection connection = new DataConnection();
        public DataTable LayDanhSach()
        {
            return connection.Read("exec SACH_Get");   
        }

        public void ThemSach(string ma, string ten, string theloai, string tacgia)
        {
            string cmd = "exec SACH_Insert '{0}',N'{1}',N'{2}',N'{3}',0";
            connection.Write(String.Format(cmd,ma,ten,tacgia,theloai));
        }

        public void CapNhatSach(string ma, string ten, string theloai, string tacgia, string soluong)
        {
            string cmd = "exec SACH_Update '{0}',N'{1}',N'{2}',N'{3}',N'{4}'";
            connection.Write(String.Format(cmd, ma, ten, tacgia, theloai, soluong));
        }

        public void CapNhatSach(string ma, string soluong)
        {
            string cmd = "exec SACH_UpdateSL '{0}',{1}";
            connection.Write(String.Format(cmd, ma, soluong));
        }

        public DataTable XemThongTinSach(string ms)
        {
            return connection.Read("select * from SACH where MaSach = '" + ms + "'");
        }

        public DataTable TimKiem(string key)
        {
            return connection.Read("exec SACH_Search '" + key+"'");
        }
        ///////////////////
        public DataTable TimKiemTheoMa(string key)
        {
            return connection.Read("exec SACH_SearchId '" + key + "'");
        }

        public DataTable TimKiemTheoTen(string key)
        {
            return connection.Read("exec SACH_SearchName '" + key + "'");
        }

        public DataTable TimKiemTheoTheLoai(string key)
        {
            return connection.Read("exec SACH_SearchType '" + key + "'");
        }

        public DataTable TimKiemTacGia(string key)
        {
            return connection.Read("exec SACH_SearchAuThor '" + key + "'");
        }
    }


}
